<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>地址列表</title>
		<script src="../js/mui.min.js"></script>
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/iconfont.css" />
		<link rel="stylesheet" href="../css/style.css" />
		<link rel="stylesheet" href="../css/member.css" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">管理收货地址</h1>
		</header>
		<div class="mui-content">
			<ul class="address_list" id="address_ul">
				<!--<li>
	    		<div class="address_top clearfix">
	    			<span class="address_name">天下大帅哥</span>
	    			<span class="address_call">18973596286</span>
	    		</div>
	    		<div class="address_info">湖南省 郴州市 北湖区 燕泉街道 青年大道天一华府C座2701</div>
	    		<div class="address_lisbtn clearfix">
	    			<div class="mui-input-row mui-checkbox mui-left">
						<label class="checked">默认地址</label>
						<input name="checkbox" value="Item 1" type="checkbox" >
					</div>
					<div class="address_btnbox">
						<a href="#"><span class="iconfont icon-yijianfankui"></span>编辑</a>
						<a href="#"><span class="iconfont icon-shanchu"></span>删除</a>
					</div>
	    		</div>
	    	</li>-->

			</ul>
		</div>
		<div class="mui-content" id="no_address" style="display: none;">
			<div class="no_style">
				<p><span class="iconfont icon-xinfeng"></span></p>
				<p class="nr"><strong>收货地址还空着</strong></p>
				<p class="wz">赶快去添加收货地址吧~</p>
			</div>
		</div>
		<div class="address_addbtn" id="add_dizhi">添加新地址</div>
	</body>

</html>

<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/app.js" type="text/javascript"></script>
<script type="text/javascript" src="../js/castapp.js"></script>
<script type="text/javascript" src="../js/jbase64.js"></script>
<script type="text/javascript" src="../js/layer/layer.min.js"></script>
<script type="text/javascript">
	$("#add_dizhi").click(function() {
		location.href = "mem_add.html";
	});
</script>
<script>
	//显示收货地址
	$(function() {
		Axis = JSON.parse(localStorage.getItem('axis'));
		var member = JSON.parse(localStorage.getItem('member'));
		getsjFoot();
		//Axis = get_user_Axis();
		$.ajax({
			//type: 'post',
			url: APP.api_url + 'member/getAddressList',
			data: {
				token: member['token'],
				uid: getUid()
			},
			success: function(data) {
				if(data.code == 200) {
					var u_id = 1;
					if(member != null) {
						u_id = member['id'];
					}
					var addressList = data.data;
					var address_htm = "";
					var checked = "";
					var moren = "";
					for(var i = 0; i < addressList.length; i++) {
						if(addressList[i].isdefault != 2) {
							checked = "";
							moren = "";
						} else {
							checked = "checked";
							moren = "<label class='checked'>默认地址</label>";
						}
						address_htm += "<li><div class='address_top clearfix'>" +
							"<span class='address_name'>" + addressList[i].realname + "</span>" +
							"<span class='address_call'>" + addressList[i].mobile + "</span></div>" +
							"<div class='address_info'>" + addressList[i].province + addressList[i].city + addressList[i].district + addressList[i].address + "</div>" +
							"<div class='address_lisbtn clearfix'>" +
							"<div class='mui-input-row mui-checkbox mui-left'>" + moren +
							"<input name='checkbox' id='check' value='Item 1' type='checkbox' " + checked + "></div>" +
							"<div class='address_btnbox'>" +
							"<a href='address_update.html?id=" + addressList[i].id + "'><span class='iconfont icon-yijianfankui'></span>编辑</a>" +
							"<a id='my_id_" + i + "' onclick='del_data(" + i + ")' data-id='" + addressList[i].id + "' href='#'>" +
							"<span class='iconfont icon-shanchu'></span>删除</a></div></div></li>";
					}
					$("#address_ul").empty();
					$("#address_ul").append(address_htm);
				} else {
					$("#no_address").show();
					console.log(data.msg);
				}
			}
		})
	});
</script>
<script>
	//删除收货地址
	var member = JSON.parse(localStorage.getItem('member'));

	function del_data(obj) {
		var address_id = $("#my_id_" + obj).data("id");
		layer.confirm('确定删除?', function() {
			$.ajax({
				//type: 'post',
				url: APP.api_url + 'Member/del_address',
				data: {
					token: member['token'],
					uid: getUid(),
					id: address_id
				},
				success: function(data) {
					if(data.code == 200) {
						layer.msg('删除成功！');
						location.href = 'address.html';
					} else {
						console.log(data.msg);
					}
				}
			})
		});
	}
</script>